
package com.sky.decorator;
/**
 * @author : wushikai
 * <p>
 * date : 2020-08-11
 */
/*-------------------------装饰模式的架构----------------------------------*/

/**抽象构建角色*/
interface Component{    //奶茶接口 就是  共性
    //业务
    public void operation();
}


/**具体构建者角色*/
class  ConcreteComponent implements Component{ // 具体的奶茶成品 例如珍珠奶茶

    public ConcreteComponent() {
        System.out.println("创建具体构件角色");

    }

    //业务
    @Override
    public void operation() {
        System.out.println("调用具体构件业务方法");
    }



}

/**抽象装饰角色*/
class Decorator implements Component{   // 表示调料

    private Component component;


    public Decorator(Component component) {
        this.component = component;
    }

    @Override
    public void operation() {
       component.operation();
    }



}


/**具体装饰角色*/
class ConcreteDecorator extends Decorator{  //表示具体调料 例如 咖啡, 果脯, 珍珠....


    public ConcreteDecorator(Component component) {
        super(component);
    }

    @Override
    public void operation() {
        super.operation();
        addedFunction();
    }

    public void addedFunction()
    {
        System.out.println("为具体构件角色增加额外的功能addedFunction()");
    }

}

class ClientTest {

    public static void main(String[] args)
    {
        Component p=new ConcreteComponent();
        p.operation();
        System.out.println("---------------------------------");
        Component d=new ConcreteDecorator(p);
        d.operation();
    }
}
